# 前端构建阶段
FROM node:16-alpine as frontend-builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# 后端运行阶段
FROM python:3.9-slim
WORKDIR /app

# 安装系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    libc6-dev \
    && rm -rf /var/lib/apt/lists/*

# 安装Python依赖
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# 复制后端代码
COPY src/backend/ ./src/backend/

# 从前端构建阶段复制静态文件
COPY --from=frontend-builder /app/dist ./src/backend/static

# 暴露后端服务端口
EXPOSE 8000

# 启动命令
CMD ["python", "src/backend/main.py"]